package com.yunji.news.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunji.news.common.Result;
import com.yunji.news.entity.RegistrationEntry;
import com.yunji.news.service.RegistrationEntryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 报名入口前台控制器
 */
@RestController
@RequestMapping("/registration-entries")
@Slf4j
public class RegistrationEntryController {

    @Autowired
    private RegistrationEntryService registrationEntryService;

    /**
     * 获取报名入口列表（前台）
     */
    @GetMapping
    public Result<Page<RegistrationEntry>> getRegistrationEntries(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "20") Integer size,
            @RequestParam(required = false) String schoolName,
            @RequestParam(required = false) Integer year,
            @RequestParam(defaultValue = "1") Integer status) {
        
        log.info("🎯 RegistrationEntryController API调用 - 版本标识: V2.0-2025-11-27-15:30 - 参数: current={}, size={}, schoolName={}, year={}, status={}", 
                current, size, schoolName, year, status);
        
        Page<RegistrationEntry> page = registrationEntryService.getRegistrationEntryPage(current, size, schoolName, year, status);
        
        log.info("✅ RegistrationEntryController API返回 - 查询到{}条记录", page.getTotal());
        
        return Result.success("", page);
    }

    /**
     * 获取报名入口详情
     */
    @GetMapping("/{id}")
    public Result<RegistrationEntry> getRegistrationEntryById(@PathVariable Long id) {
        RegistrationEntry registrationEntry = registrationEntryService.getById(id);
        if (registrationEntry == null) {
            return Result.error("报名入口不存在");
        }
        return Result.success("", registrationEntry);
    }
}